package com.nit.ehcache.service;

import com.nit.ehcache.dto.WeatherDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class WeatherManager {

    /**
     * 获取数据
     * @param id
     * @return
     */
    @Cacheable(cacheNames = "weather", key = "#id")// 从缓存获取，key为ID，缓存具体看 ehcache.xml 配置文件
    public WeatherDto getById(String id) {
        log.info("WeatherManager#getById: id={}", id);
        System.out.println("查数据库");
        WeatherDto weatherDto = new WeatherDto();
        weatherDto.setMessage("今天天晴");
        weatherDto.setId(127727L);
        weatherDto.setStatus(200);
        return weatherDto;
    }

}
